package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.mapper.ContractMapper;
import com.zzyl.nursing.service.IContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author guomo
 */
@Slf4j
@Component("contractTask")
public class ContractTask {

    @Autowired
    private IContractService contractService;

    // 定义一个public方法contractStatusCheck，用于校验合同状态
    public void contractStatusCheck() {
        LambdaUpdateWrapper<Contract> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Contract::getStatus, 0);
        updateWrapper.set(Contract::getStatus, 1);
        updateWrapper.lt(Contract::getStartDate, LocalDateTime.now());
        updateWrapper.gt(Contract::getEndDate, LocalDateTime.now());
        contractService.update(updateWrapper);
        LambdaUpdateWrapper<Contract> updateWrapper1 = new LambdaUpdateWrapper<>();
        updateWrapper1.eq(Contract::getStatus, 1);
        updateWrapper1.set(Contract::getStatus, 2);
        updateWrapper1.lt(Contract::getEndDate, LocalDateTime.now());
        contractService.update(updateWrapper1);
    }

}
